<?php
class latestPosts {
    function set_page($new_page) {
        $this->pageid = $new_page;
        return $this->pageid;
    }

    function set_id($new_id) {
        $this->id = $new_id;
        return $this->id;
    }

    function get_latestPosts() {
        $connect = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        $query = $connect->query("SELECT SUBSTRING(title, 1, 50 )AS shortTitle, title, id, time, thumb FROM ".$prefix."posts WHERE draft = '0' ORDER BY id DESC LIMIT 5");

        while($row = $query->fetch_object()) {
            $time = date('m-d',strtotime($row->time));

            if($row->shortTitle < $row->title) {
                $shortTitle = $row->shortTitle.'...';
            }
            else {
                $shortTitle = $row->shortTitle;
            }

            $this->postlist[] = array(
                "time" => $time,
                "id" => $row->id,
                "shortTitle" => $shortTitle,
                "title" => $row->title
            );
        }
        return $this->postlist;
        $query->close();
        $connect->close();
    }
}
?>
